/*
*  SkyOGGDecoder.h
*  
*
*  Created by Alexander Trutchenko on 11/02/12.
*  Copyright 2012 Free Team. All rights reserved.
*
*/

#ifndef __Sky_OGGDecoder_h__
#define __Sky_OGGDecoder_h__

#include "SkyDefines.h"
#include "SkyDecoder.h"

#include "vorbis/vorbisfile.h"

namespace sky {

#define SKY_OGG_DECODED_EXT "ogg"

////////////////////////////////////////////////////////
//
/** SkyOGGStaticDecoder
*  
*/
////////////////////////////////////////////////////////

class SkyOGGStaticDecoder : public SkyStaticDecoder
{
protected:
	~SkyOGGStaticDecoder();

public:
	SkyOGGStaticDecoder();
	

public:
	virtual ALuint getBufferIDFromFileData(const SkyFileData& fileData) const; 
	virtual SkyMemoryWrapper* getPCMDataFromFileData(const SkyFileData& fileData, SkyBufferHeader& header) const; 

}; //class SkyStaticDecoder

////////////////////////////////////////////////////////
//
/** SkyOGGStreamFileData
*  
*/
////////////////////////////////////////////////////////

class SkyOGGStreamFileData : public SkyStreamFileData
{
	OggVorbis_File* _mVF;
public:
	SkyOGGStreamFileData(SkyBufferManager* bufferManager, const SkyFileData* fileData);
	SkyOGGStreamFileData(SkyBufferManager* bufferManager, const char* file);
	virtual ~SkyOGGStreamFileData();

public:
	virtual bool isSeekable() const { return true; }
	virtual void seek(float position); // position = [0.f .. 1.f]
	virtual unsigned int readBlock(void* buffer, int desirableDecodeSize);

private:
	void initOgg();

}; //class SkyStreamDecoder

////////////////////////////////////////////////////////
//
/** SkyStreamDecoder
*  
*/
////////////////////////////////////////////////////////



class SkyOGGStreamDecoder : public SkyStreamDecoder
{
	
public:
	SkyOGGStreamDecoder(SkyStreamData* streamData);
	virtual ~SkyOGGStreamDecoder();

public:
	virtual void seek(float position); // position = [0.f .. 1.f]
	virtual SkyMemoryWrapper* readBlock(int desirableDecodeSize); // returns decoded size

}; //class SkyOGGStreamDecoder

////////////////////////////////////////////////////////
//
/** SkyStreamDecoderFactory
*  
*/
////////////////////////////////////////////////////////

class SkyOGGStreamDecoderFactory : public SkyStreamDecoderFactory
{
public:
	SkyOGGStreamDecoderFactory() {;}
	virtual ~SkyOGGStreamDecoderFactory() {;}

public: 
	virtual SkyStreamDecoder* createDecoder(SkyStreamData* streamData) const
	{
		return new SkyOGGStreamDecoder(streamData);
	}
	virtual SkyStreamFileData* createStreamFileData(SkyBufferManager* bufferManager, const char* file) const	
	{
		return new SkyOGGStreamFileData(bufferManager, file);
	}
};

} // namespace sky

#endif //__Sky_OGGDecoder_h__
